package com.cloud.auth.service.impl;

import com.cloud.auth.mapper.BaseMapper;
import com.cloud.auth.mapper.UserMapper;
import com.cloud.auth.service.UserService;
import com.cloud.auth.util.DateUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;


/**
 * @packageName: com.api.service.auth.impl
 * @name: UserServiceImpl
 * @description:
 * @author: 董定卓
 * @dateTime: 2019/6/13 17:33
 */
@Service("userService")
public class UserServiceImpl extends BaseServiceImpl implements UserService {

    @Autowired
    UserMapper mapper;

    @Override
    protected BaseMapper getMapper() {
        return mapper;
    }

    /**
     * 用户登录
     *
     * @param map
     * @return
     */
    @Override
    public  Map<String,Object> login(Map<String, Object> map) {
        return mapper.login(map);
    }

    @Override
    public int add(Map<String, Object> map) {
        int i = mapper.insert(map);
        if (i > 0) {
            map.get("id");
            map.put("userId", map.get("id"));
            map.put("createTime", DateUtil.currentSeconds());
            int j = mapper.insertUser(map);
            if (j > 0) {
                return j;
            }
        }
        return 0;
    }

    /**
     * 根据用户ID获取用户权限
     *
     * @param userId
     * @return
     */
    @Override
    public List<Map<String, Object>> listPermissionByUserId(String userId) {
        return mapper.listPermissionByUserId(userId);
    }

    /**
     * 修改个人基本信息(真实姓名等)
     *
     * @param map
     * @return
     */
    @Override
    public int updateUser(Map<String, Object> map) {
        return mapper.updateUser(map);
    }
}
